var ctx;
var phoneReg = /^(0[0-9]{2,3}\-?)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$|(^(13[0-9]|15[0-9]|18[5|6|8|9])\d{8}$)/;

function setCtx(ctx){
	this.ctx = ctx;
}

function ifNull(mess){
	if(mess == null || mess == undefined){
		mess = "";
	}
	return mess;
}

//验证手机
function checkPhone(){
	 var phone = $("#phone").val();
	//解决ie9以下placeholder与value重复的问题
		if(phone == $("#phone").attr("placeholder") ){
			phone = "";
		}
		if(phone == null || phone == ""){
				layer.tips('手机号不能为空!', '#phone',{
				    tips: 3,
				    time:1000
				});
				return false;
			}else{
				if(!phoneReg.test(phone)){
					layer.tips('手机号格式错误，请填写正确格式的手机号!有区号的必须加上短横线，如：027-87878787；027-59595959', '#phone', {
					    tips: 3,
					    time:2000
					});
					return false;
				}else{
					return true;
				}
			}
}

//验证手机
function checkPhone2(){
	 var phone2 = $("#phone2").val();
	//解决ie9以下placeholder与value重复的问题
		if(phone2 == $("#phone2").attr("placeholder") ){
			phone2 = "";
		}
		if(phone2 == null || phone2 == ""){
				layer.tips('手机号不能为空!', '#phone2',{
				    tips: 3,
				    time:1000
				});
				return false;
			}else{
				if(!phoneReg.test(phone2)){
					layer.tips('手机号格式错误，请填写正确格式的手机号!', '#phone2', {
					    tips: 3,
					    time:1000
					});
					return false;
				}else{
					return true;
				}
			}
}


//全选和反选
function selectAll(target){    
    if(target.checked){    
        $("#tableTbody :checkbox").attr("checked", true); 
        $(target).parents("thead").siblings("tbody").children().children().each(function(){
    	    $(this).css("background","#D3F0F1");
       });
    }else{    
        $("#tableTbody :checkbox").attr("checked", false); 
        $(target).parents("thead").siblings("tbody").children().children().each(function(){
    	    $(this).css("background","");
       });
    }    
}

//鼠标滑入一行改变背景颜色
function mouseoverOne(target){
	 $(target).children().each(function(){
		  	    $(this).css("background","#D3F0F1");
		     });
}

//鼠标滑出一行恢复原来的背景颜色
function mouseoutOne(target){
	 $(target).children().each(function(){
	  	    $(this).css("background","");
	     });
}

//选择或取消选中当前记录
function selectOne(id,target){
    if(target.checked){    
        $("#goods" + id).attr("checked", true);   
        $(target).parents("tr").children().each(function(){
    	    $(this).css("background","#D3F0F1");
       });
    }else{    
        $("#goods" + id).attr("checked", false); 
        $(target).parents("tr").children().each(function(){
    	    $(this).css("background","");
       });
    } 
}

//保存方法
function saveShopInfo() {
	var descrip = $('#descrip').val();
	var beginTime = $('#beginTime').val();
	var endTime = $('#endTime').val();
	var phone = $('#phone').val();
	var phone2 = $('#phone2').val();
	var address = $('#address').val();
	var shopId = $('#shopId').val();
	var imageLogo = $('#imageLogo').val();
	
	if(checkPhone() && checkPhone2()){
			$.ajax({
				type : "POST",
				url : ctx + "/storeInfo/UpdateStoreInfo",
				cache : false,
				dataType : 'json',
				data: {
					descrip : descrip,
					beginTime : beginTime,
					endTime : endTime,
					phone : phone,
					phone2 : phone2,
					address : address,
					logo : imageLogo
				},
				success : function(result) {
					if (result.success) {
						//alert("操作成功");
						layer.msg("操作成功",{
							icon: 1,
							time: 3000 //2秒关闭（如果不配置，默认是3秒）
						},function(){
							loadContent("/storeInfo/storeInfoList");
						});
					} else {
						layer.msg("操作失败",{
							icon: 2
						});
					}
				}
			});
	}		
}




